package com.wuhunyu.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.excel.metadata.CellData;
import com.wuhunyu.entities.excel.SubjectData;
import com.wuhunyu.service.EduSubjectService;
import javax.annotation.Resource;
import java.util.Map;

/**
 * 添加课程监听器
 *
 * @author wuhunyu
 * @version 1.0
 * @date 2021-01-16 15:00
 */
public class EduSubjectListener extends AnalysisEventListener<SubjectData> {

    @Resource
    private EduSubjectService eduSubjectService;

    public EduSubjectListener() {
    }

    public EduSubjectListener(EduSubjectService eduSubjectService) {
        this.eduSubjectService = eduSubjectService;
    }

    @Override
    public void invokeHead(Map<Integer, CellData> headMap, AnalysisContext context) {

    }

    @Override
    public void invoke(SubjectData subjectData, AnalysisContext analysisContext) {
        // 添加一行数据
        eduSubjectService.addSubjectDetail(subjectData.getOneSubjectName(), subjectData.getTwoSubjectName());
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }
}
